package user

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method 'GET'
        url('/api/users') {
            queryParameters {
                parameter("nameOrEmail", "@qq")
            }
        }
    }
    response {
        status 200
        body("""
                  [
                    {
                        "id": 1,
                        "username": "zhang",
                        "email": "zhang@qq.com",
                        "mobilePhone": "12345678901"
                    }
                  ]
                """)
        bodyMatchers {
            jsonPath('$[*]',byType())
            jsonPath('$[*].id', byRegex(number()))
            jsonPath('$[*].username', byRegex(onlyAlphaUnicode()))
            jsonPath('$[*].email', byRegex(email()))
            jsonPath('$[*].mobilePhone', byRegex(number()))

        }
        headers {
            header('Content-Type': 'application/json;charset=UTF-8')
        }
    }
}
